from fastapi import FastAPI
from .request_context import RequestContextMiddleware
from .response import ResponseMiddleware
from .permission import PermissionMiddleware
from .timezone import TimezoneMiddleware
from .access_log import AccessLogMiddleware


def init_middleware(app: FastAPI) -> None:
    # 请求上下文中间件应该最先执行
    app.add_middleware(RequestContextMiddleware)
    # 权限中间件在请求上下文之后执行
    # app.add_middleware(PermissionMiddleware)
    # 响应处理中间件最后执行
    app.add_middleware(ResponseMiddleware)
    # 时区中间件在响应处理中间件之后执行
    app.add_middleware(TimezoneMiddleware)
    # 访问日志中间件在时区中间件之后执行
    app.add_middleware(AccessLogMiddleware)
